package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.dataservice.cache.DcPublicCache;
import com.iwhalecloud.bss.kite.dataservice.entity.DcPublic;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteOfferInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteSceneInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;
import com.ztesoft.bss.common.util.SpringUtil;

import java.util.List;
import java.util.Optional;

/**
 * @Classname InitiatorUserIdAttrHandler
 * @Description 发起方用户标识，落地方隐藏，收费方显示
 * @Author zhang.song
 * @Date 2022-02-14 17:01
 */
public class InitiatorUserIdAttrHandler extends AbstractAttrHandler<KiteInst, AttrData> {

    @Override
    public void after(KiteAttr attr, KiteInst inst, AttrData data) {
        IQuerySceneInstService querySceneInstService = SpringUtil.getBean(IQuerySceneInstService.class);
        KiteSceneInst sceneInst = querySceneInstService.getSceneInst(data.getSceneInstId());
        KiteOfferInst offerInst = querySceneInstService.getOfferInst(sceneInst.getCustId(), sceneInst.getRootInstId());
        String offerId = Optional.ofNullable(offerInst).map(KiteOfferInst::getOfferId).orElse(null);
        List<DcPublic> list = DcPublicCache.get("20210719001");
        // 是否五大双线收费方产品
        boolean flag = (list != null) && list.stream().anyMatch(dcPublic -> KiteStringUtils.isEqual(offerId, dcPublic.getCodeb()) && KiteStringUtils.isEqual(dcPublic.getCodec(), "2"));
        if(flag) {
            attr.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_D);
        } else {
            attr.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_H);
        }
        super.after(attr, inst, data);
    }
}
